﻿#include "datasource.h"
#include "./include/settings.h"
#include "include/settings.h"
DataSource::DataSource(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
#if 1
	setWindowFlags(Qt::Window | Qt::FramelessWindowHint
		| Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint
		| Qt::WindowMaximizeButtonHint);

    this->setAutoFillBackground(true);
    QPalette palette;
    palette.setColor(QPalette::Background, QColor(30,144,255));
    this->setPalette(palette);

	QPainterPath path;
	QRectF rect = QRectF(this->rect());
	path.addRoundRect(rect,5,5);
	QPolygon polygon= path.toFillPolygon().toPolygon();
	QRegion region(polygon);
	setMask(region);
#endif
	connect(ui.pushButton_ok, SIGNAL(clicked()),this,SLOT(ok()));

    DataSourceType type = (DataSourceType)Settings::readDataSouce();
    if(type == UART)
         ui.radioButtonUart->setChecked(true);
    else if(type == NET)
        ui.radioButtonNet->setChecked(true);
    else if(type == UART_AND_NET)
        ui.radioButtonNetAndUart->setChecked(true);
    else
    {}
}

void DataSource::ok()
{
	if(ui.radioButtonUart->isChecked())
        Settings::setDataSouce(UART);
	else if(ui.radioButtonNet->isChecked()){
        Settings::setDataSouce(NET);
    }
     else if(ui.radioButtonNetAndUart->isChecked()){
        Settings::setDataSouce(UART_AND_NET);
	}
	else
		Settings::setDataSouce(-1);
	this->close();
}

DataSource::~DataSource()
{
}
void DataSource::closeEvent(QCloseEvent *)
{
    delete this;  //pointer object
}
